package com.lijie.redission.controller;

import com.lijie.redission.common.redisDelayQueue.RedisDelayQueueEnum;
import com.lijie.redission.common.redisDelayQueue.RedisDelayQueueUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @author 李杰
 * @create 2024-05-28-9:58
 */
@Slf4j
@RestController
@RequestMapping("/test")
public class LjTestController {
    @Autowired
    private RedisDelayQueueUtil redisDelayQueueUtil;

    @GetMapping("/addQueue")
    public void addQueue(@RequestParam("orderId") String orderId) {
        Map<String, String> map1 = new HashMap<>();
        map1.put("orderId", orderId);
        map1.put("remark", "订单支付超时，自动取消订单");

        // 为了测试效果，延迟10秒钟
        redisDelayQueueUtil.addDelayQueue(map1, 5, TimeUnit.SECONDS, RedisDelayQueueEnum.ORDER_PAYMENT_TIMEOUT.getCode());
    }
    @GetMapping("/removeQueue")
    public void removeQueue(@RequestParam("orderId") String orderId) {
        Map<String, String> map1 = new HashMap<>();
        map1.put("orderId", orderId);
        map1.put("remark", "订单支付超时，自动取消订单");

        // 为了测试效果，延迟10秒钟
        redisDelayQueueUtil.removeDelayedQueue(map1, RedisDelayQueueEnum.ORDER_PAYMENT_TIMEOUT.getCode());
        log.info("订单已审核，去掉定时取消任务 ({})",orderId);
    }

}
